package com.hzw.saas.api.old.storage.enums;

import java.util.Objects;

import com.hzw.saas.common.config.util.AssertUtil;


/**
 * 存储空间
 *
 * @author zzl
 * @since 02/26/2021
 */
public enum SpaceTypeEnum {

    PERSONAL_SPACE(100, "personal_space"),
    WORK_SPACE(200, "work_space"),
    ;

    private final Integer code;
    private final String text;

    SpaceTypeEnum(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    public Integer code() {
        return code;
    }

    public String text() {
        return text;
    }

    public static String text(Integer code) {
        for (SpaceTypeEnum value : SpaceTypeEnum.values()) {
            if (Objects.equals(value.code, code))
                return value.text;
        }
        return null;
    }

    public static SpaceTypeEnum instance(Integer code) {
        return instance(code, false);
    }

    public static SpaceTypeEnum instance(Integer code, boolean throwUnknown) {
        for (SpaceTypeEnum value : SpaceTypeEnum.values()) {
            if (Objects.equals(value.code, code))
                return value;
        }
        AssertUtil.assertThrow("存储空间代码异常，请设置正确的空间码", throwUnknown);
        return null;
    }
}
